#include <iostream>
#include <cstdio>
#include <sys/wait.h>
#include <sys/types.h>
#include <unistd.h>
#include <cstring>
#include <stdlib.h>
using namespace std;

int main()
{
    //创建一个匿名管道
    int pipefd[2] = {0};
    int n = pipe(pipefd);
    if(n == 0)
    {
        perror("pipe create");
    }
    //创建子进程
    pid_t id = fork();
    if(id == 0)
    {
        //子进程关闭读端
        close(pipefd[0]);
        const char* msg = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
        while(true)
        {
            write(pipefd[1],msg,strlen(msg));
        }
        
    }
    close(pipefd[0]);
    int status = 0;
    waitpid(id, &status,0);
    cout << "我是父进程,我的pid是:" << getpid() << " 子进程的退出信号为：" << (status & 0x7F) << endl;
    return 0;
}